//
//  ZJMessageEarlyViewController.m
//  ZJControlsClass
//
//  Created by wandoufo on 2024/12/6.
//

#import "ZJMessageEarlyViewController.h"
#import <Masonry/Masonry.h>
#import "ZJMessageEarlyTableViewCell.h"

@interface ZJMessageEarlyViewController () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *timeLabel;
@property (nonatomic, strong) UILabel *peopleCountLabel;

@end

@implementation ZJMessageEarlyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"低分预警";
    [self setupUI];
}

- (void)setupUI {
    // 设置顶部信息
    self.peopleCountLabel = [[UILabel alloc] init];
    self.peopleCountLabel.text = @"人数：3";
    [self.view addSubview:self.peopleCountLabel];
    
    self.timeLabel = [[UILabel alloc] init];
    self.timeLabel.text = @"预警时间：2024-12-04 09:13:49";
    [self.view addSubview:self.timeLabel];
    
    // 设置表格
    self.tableView = [[UITableView alloc] init];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.tableView];
    
    // 注册自定义Cell
//    [self.tableView registerClass:[ZJMessageEarlyTableViewCell class] forCellReuseIdentifier:@"ZJMessageEarlyTableViewCell"];
    
    // 添加表头视图
    UIView *headerView = [self createTableHeaderView];
    self.tableView.tableHeaderView = headerView;
    
    // 布局约束
    [self.peopleCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(12);
//        make.width.mas_equalTo(80);
        make.top.equalTo(self.view).offset(10 + StatusBarHeight);
    }];
    
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(12);
//        make.width.mas_equalTo(80);
        make.top.equalTo(self.peopleCountLabel.mas_bottom).offset(10);
    }];
    
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(12);
        make.right.equalTo(self.view).offset(-12);
        make.top.equalTo(self.timeLabel.mas_bottom).offset(10);
        make.bottom.equalTo(self.view);
    }];
}

- (UIView *)createTableHeaderView {
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width - 24, 44)];
    headerView.backgroundColor = [UIColor colorWithRed:0.96 green:0.96 blue:0.96 alpha:1.0];
    
    NSArray *titles = @[@"姓名", @"分数", @"备案单位"];
    CGFloat width = headerView.frame.size.width / 3;
    
    for (NSInteger i = 0; i < titles.count; i++) {
        UILabel *label = [[UILabel alloc] init];
        label.text = titles[i];
        label.textAlignment = NSTextAlignmentCenter;
        label.frame = CGRectMake(i * width, 0, width, 44);
        [headerView addSubview:label];
    }
    
    return headerView;
}

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 6; // 根据实际数据修改
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 44;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ZJMessageEarlyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ZJMessageEarlyTableViewCell"];
//    ZJMessageTableViewCell *cell = [tableVi/*e*/w dequeueReusableCellWithIdentifier:cellID];
    if (!cell) {
        cell = [[ZJMessageEarlyTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ZJMessageEarlyTableViewCell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
//        cell.backgroundColor = [UIColor clearColor];
    }
    // 示例数据
    if (indexPath.row == 0) {
        cell.nameLabel.text = @"张三";
        cell.scoreLabel.text = @"3";
        cell.departmentLabel.text = @"安航部";
    } else {
        cell.nameLabel.text = @"王五";
        cell.scoreLabel.text = @"4";
        cell.departmentLabel.text = @"南方航空";
    }
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
